//
//  XYErrorView.swift
//  XYReadBook
//
//  Created by fox on 2017/9/6.
//  Copyright © 2017年 tsaievan. All rights reserved.
//

import UIKit

/*
 1.没有数据,比如请求回来dataArr.count == 0
 2.没有网络,且也没有缓存数据
 
 */
/// 请求失败
enum ErrorType:String {
    case errorNotWork = "errorNotWork"
    case errorNetData = "errorNotData"

}
class XYErrorView: UIView {

    /// 重写无网络点击事件
    var overrideLoadData:(() ->Void)?
    var errorType:ErrorType
    var errorBtn:UIButton!
     init(frame: CGRect,errorType:ErrorType) {
        self.errorType = errorType
        super.init(frame: frame)
        showError()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func errorLoadData () {
        overrideLoadData?()
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        errorBtn.frame = self.frame
    }

    func showError() {
        errorBtn = UIButton.init()
        errorBtn.setImage(UIImage.init(named: errorType.rawValue), for: .normal)
        errorBtn.setImage(UIImage.init(named: errorType.rawValue), for: .highlighted)
        errorBtn.imageView?.contentMode = .scaleAspectFill
        errorBtn.addTarget(self, action: #selector(errorLoadData), for: .touchUpInside)
        addSubview(errorBtn)
    }

}
